package sanrenxing.dayEnd.backRepertoryTotal.controller;


import org.springframework.web.bind.annotation.*;
import sanrenxing.dayEnd.backRepertoryTotal.domain.logMsg;
import sanrenxing.dayEnd.backRepertoryTotal.service.impl.LogmsgIm;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/lc")
public class LogmsgController {
    @Resource
    private LogmsgIm logmsgIm;
    @GetMapping("/lm")
    public Map usl(int limit, int page, HttpServletRequest re){
        logMsg su=new logMsg();
        if(limit==0){
            limit=5;
        }
        if(page==0){
            page=1;
        }
        System.out.println(limit);
        System.out.println(page);
        if(re.getParameter("userName")!=null&&re.getParameter("userName").trim().length()>0){
            su.setUserName(re.getParameter("userName"));
        }

        if(re.getParameter("visitTime")!=null&&re.getParameter("visitTime").trim().length()>0){
            su.setVisitTime(re.getParameter("visitTime"));
        }
        String xx=logmsgIm.xx(su);
        for (logMsg logMsgf : logmsgIm.all(xx, limit, page)) {
            System.out.println(logMsgf.getIpAddress());
        }
        Map<String,Object> ma=new HashMap<>();
        ma.put("code",0);
        ma.put("msg","");
        ma.put("count",logmsgIm.count(xx));
        ma.put("data",logmsgIm.all(xx,limit,page));
        return ma;
    }
    @DeleteMapping("/uss/{id}")
    public String xg(@PathVariable("id") int us){
        return logmsgIm.del(us)>0?"cg":"sb";
    }
    @PutMapping("/uss/{ss}")
    public String dels(@PathVariable("ss") String ss){
        return logmsgIm.dels(ss)>0?"cg":"sb";
    }

}
